home *** CD-ROM | disk | FTP | other *** search
- Path: newsstand.cit.cornell.edu!ub!newserve!rebecca!rpi!not-for-mail
- From: clamage@Eng.Sun.COM (Steve Clamage)
- Newsgroups: comp.lang.c++,comp.lang.c++.moderated
- Subject: Re: Defining Classes and Class Functions extern: 2 Line Sample
- Date: 1 Feb 1996 17:06:12 -0000
- Organization: Sun Microsystems Inc., Mountain View, CA
- Sender: cppmods@netlab.cs.rpi.edu
- Approved: devitto@ferndown.ate.slb.com
- Message-ID: <4eqru4$bhg@netlab.cs.rpi.edu>
- References: <4em2dn$kio@netlab.cs.rpi.edu>
- NNTP-Posting-Host: netlab.cs.rpi.edu
- X-Original-Date: 1 Feb 1996 06:35:43 GMT
-
- ivo.welch@AGSM.UCLA.EDU (Ivo Welch) writes:
-
- >Why does the following not work?
- > class tryclass;
- > extern int tryclass::tryclassfun(int w);
-
- Because you are not allowed to mention a class member unless the
- class definition is visible. For one thing, allowing this sort
- of thing would allow you in principle to insert members into a
- class without modifying the class. More importantly, the compiler
- might not have the information it needs to deal with a call to
- the member function without seeing the whole class definition.
-
- Some languages allow you to do all of these things, but C++ does not.
-
- >Is there an equivalent recommended way of hiding many member
- >functions/declarations from a particular file?
-
- A common technique is to put only a pointer to an undefined
- implementation class in the main class header file. Only the
- implementation of the functions for that class ever see
- the hidden class.
-
- class FooImpl; // forward declaration, FooImpl does all the work
-
- class Foo { // this is what users see
- private:
- FooImpl* impl;
- public:
- ... all the member functions of Foo call FooImpl functions
- };
-
- This technique, described in many C++ books, can be used to hide
- all or some of the implementation details of Foo from users of
- Foo. In particular, it means that implementation details can
- be changed without requiring that clients of Foo be recompiled.
- That is, you can add, remove, or reorder any and all of the
- members of FooImpl at will. Only the member functions of Foo
- need to be recompiled.
- --
- Steve Clamage, stephen.clamage@eng.sun.com
-
- [ Articles to moderate: mailto:c++-submit@netlab.cs.rpi.edu ]
- [ Read the C++ FAQ: http://www.connobj.com/cpp/cppfaq.htm ]
- [ Moderation policy: http://www.connobj.com/cpp/guide.htm ]
- [ Comments? mailto:c++-request@netlab.cs.rpi.edu ]
-